# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[threading.Thread.__init__(self)
log.debug('Preparing joystick plugin...')
self.setDaemon(True)
self.setName('JoystickPlugin')
self.dev = open('/dev/input/js0')
self.pos = [0, 0]
self.max_val = 32768
self.button = events.BUTTON0.post
self.mouse = events.MOUSE.post
self.start_pos = None
descriptor_watch(self.dev.fileno(), self.handle)
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x8faceec>}
nname: 0
n 0(None)[return int(100 + (val - self.max_val) * 0.00152587890625)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x8fac6ec>}
nname: 409
n 409(None)[return None
]:
	i: 391(), 395(), 408(AE)
	o: 

nname: 395
n 395(None)[PRINT_EXCEPTION()
]:
	i: 0(except)
	o: 409()

nname: 391
n 391(None)[]:
	i: 192(JA), 236(), 357(JA), 377(), 390()
	o: 409()

nname: 390
n 390(None)[]:
	i: 334(f)
	o: 391()

nname: 377
n 377(None)[self.start_pos = None
]:
	i: 350(f)
	o: 391()

nname: 357
n 357(None)[self.start_pos = self.pos + []
]:
	i: 350(t)
	o: 391(JA)

nname: 350
n 350(value)[]:
	i: 334(t)
	o: 357(t), 377(f)

nname: 334
n 334(evt == self.JS_EVENT_BUTTON)[]:
	i: 3(f)
	o: 350(t), 390(f)

nname: 236
n 236(None)[self.button(dict(x=x, y=y, start_x=self.start_pos[0], start_y=self.start_pos[1]))
self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
]:
	i: 162(f)
	o: 391()

nname: 192
n 192(None)[self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
]:
	i: 162(t)
	o: 391(JA)

nname: 162
n 162(self.start_pos is None)[x, y = self.pos
]:
	i: 96(), 135(), 161()
	o: 192(t), 236(f)

nname: 161
n 161(None)[]:
	i: 122(f)
	o: 162()

nname: 135
n 135(None)[self.pos[1] = self._adapt_ratio(value)
]:
	i: 122(t)
	o: 162()

nname: 122
n 122(number == 1)[]:
	i: 83(f)
	o: 135(t), 161(f)

nname: 96
n 96(None)[self.pos[0] = self._adapt_ratio(value)
]:
	i: 83(t)
	o: 162()

nname: 83
n 83(number == 0)[]:
	i: 3(t)
	o: 96(t), 122(f)

nname: 3
n 3(evt == self.JS_EVENT_AXIS)[evt = self.dev.read(self.JS_EVENT_SIZE)
time, value, type, number = unpack(self.JS_EVENT, evt)
evt = type & ~self.JS_EVENT_INIT
]:
	i: 0(try)
	o: 83(t), 334(f)

nname: 0
n 0(None)[]:
	i: 
	o: 3(try), 395(except)

nname: 409
n 409(None)[return None
]:
	i: 395(), 83(JA), 334(JA)
	o: 

nname: 395
n 395(None)[except:
	PRINT_EXCEPTION()
]:
	i: 0()
	o: 409()

nname: 334
n 334(None)[if evt == self.JS_EVENT_BUTTON:
	if value:
		self.start_pos = self.pos + []
	else:
		self.start_pos = None
]:
	i: 0(f)
	o: 409(JA)

nname: 83
n 83(None)[if number == 0:
	self.pos[0] = self._adapt_ratio(value)
else:
	if number == 1:
		self.pos[1] = self._adapt_ratio(value)
x, y = self.pos
if self.start_pos is None:
	self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
else:
	self.button(dict(x=x, y=y, start_x=self.start_pos[0], start_y=self.start_pos[1]))
	self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
]:
	i: 0(t)
	o: 409(JA)

nname: 0
n 0(evt == self.JS_EVENT_AXIS)[try:
	evt = self.dev.read(self.JS_EVENT_SIZE)
	time, value, type, number = unpack(self.JS_EVENT, evt)
	evt = type & ~self.JS_EVENT_INIT
]:
	i: 
	o: 83(t), 334(f), 395()

nname: 409
n 409(None)[return None
]:
	i: 395(), 0(JA)
	o: 

nname: 0
n 0(None)[try:
	evt = self.dev.read(self.JS_EVENT_SIZE)
	time, value, type, number = unpack(self.JS_EVENT, evt)
	evt = type & ~self.JS_EVENT_INIT
if evt == self.JS_EVENT_AXIS:
	if number == 0:
		self.pos[0] = self._adapt_ratio(value)
	else:
		if number == 1:
			self.pos[1] = self._adapt_ratio(value)
	x, y = self.pos
	if self.start_pos is None:
		self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
	else:
		self.button(dict(x=x, y=y, start_x=self.start_pos[0], start_y=self.start_pos[1]))
		self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
else:
	if evt == self.JS_EVENT_BUTTON:
		if value:
			self.start_pos = self.pos + []
		else:
			self.start_pos = None
]:
	i: 
	o: 409(JA)

self.nodes: {0: <unpyclib.structure.node instance at 0x8fb33ec>, 409: <unpyclib.structure.node instance at 0x8fb73ec>, 395: <unpyclib.structure.node instance at 0x8fb72ec>}
nname: 6
n 6(None)[__doc__ = '\n    Input plugin for joystick device based on linux input event interface.\n    Used for now for uwand rcu\n    '
JS_EVENT_BUTTON = 1
JS_EVENT_AXIS = 2
JS_EVENT_INIT = 128
JS_EVENT = 'IhBB'
JS_EVENT_SIZE = calcsize(JS_EVENT)
def __init__(self, *args):
	threading.Thread.__init__(self)
	log.debug('Preparing joystick plugin...')
	self.setDaemon(True)
	self.setName('JoystickPlugin')
	self.dev = open('/dev/input/js0')
	self.pos = [0, 0]
	self.max_val = 32768
	self.button = events.BUTTON0.post
	self.mouse = events.MOUSE.post
	self.start_pos = None
	descriptor_watch(self.dev.fileno(), self.handle)
	return None

def _adapt_ratio(self, val):
	return int(100 + (val - self.max_val) * 0.00152587890625)

def handle(self):
	try:
		evt = self.dev.read(self.JS_EVENT_SIZE)
		time, value, type, number = unpack(self.JS_EVENT, evt)
		evt = type & ~self.JS_EVENT_INIT
	if evt == self.JS_EVENT_AXIS:
		if number == 0:
			self.pos[0] = self._adapt_ratio(value)
		else:
			if number == 1:
				self.pos[1] = self._adapt_ratio(value)
		x, y = self.pos
		if self.start_pos is None:
			self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
		else:
			self.button(dict(x=x, y=y, start_x=self.start_pos[0], start_y=self.start_pos[1]))
			self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
	else:
		if evt == self.JS_EVENT_BUTTON:
			if value:
				self.start_pos = self.pos + []
			else:
				self.start_pos = None

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0x8fa3f0c>}
nname: 0
n 0(None)[import threading
from struct import unpack, calcsize
import struct
import pygui.eventmanager.events as events
from peewee.notifier import descriptor_watch
from peewee.debug import GET_LOGGER, PRINT_EXCEPTION
log = GET_LOGGER(__name__)
class PluginInterface(.):
	__doc__ = '\n    Input plugin for joystick device based on linux input event interface.\n    Used for now for uwand rcu\n    '
	JS_EVENT_BUTTON = 1
	JS_EVENT_AXIS = 2
	JS_EVENT_INIT = 128
	JS_EVENT = 'IhBB'
	JS_EVENT_SIZE = calcsize(JS_EVENT)
	def __init__(self, *args):
		threading.Thread.__init__(self)
		log.debug('Preparing joystick plugin...')
		self.setDaemon(True)
		self.setName('JoystickPlugin')
		self.dev = open('/dev/input/js0')
		self.pos = [0, 0]
		self.max_val = 32768
		self.button = events.BUTTON0.post
		self.mouse = events.MOUSE.post
		self.start_pos = None
		descriptor_watch(self.dev.fileno(), self.handle)
		return None

	def _adapt_ratio(self, val):
		return int(100 + (val - self.max_val) * 0.00152587890625)

	def handle(self):
		try:
			evt = self.dev.read(self.JS_EVENT_SIZE)
			time, value, type, number = unpack(self.JS_EVENT, evt)
			evt = type & ~self.JS_EVENT_INIT
		if evt == self.JS_EVENT_AXIS:
			if number == 0:
				self.pos[0] = self._adapt_ratio(value)
			else:
				if number == 1:
					self.pos[1] = self._adapt_ratio(value)
			x, y = self.pos
			if self.start_pos is None:
				self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
			else:
				self.button(dict(x=x, y=y, start_x=self.start_pos[0], start_y=self.start_pos[1]))
				self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
		else:
			if evt == self.JS_EVENT_BUTTON:
				if value:
					self.start_pos = self.pos + []
				else:
					self.start_pos = None



]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x8fa320c>}
import threading
from struct import unpack, calcsize
import struct
import pygui.eventmanager.events as events
from peewee.notifier import descriptor_watch
from peewee.debug import GET_LOGGER, PRINT_EXCEPTION
log = GET_LOGGER(__name__)
class PluginInterface(.):
	__doc__ = '\n    Input plugin for joystick device based on linux input event interface.\n    Used for now for uwand rcu\n    '
	JS_EVENT_BUTTON = 1
	JS_EVENT_AXIS = 2
	JS_EVENT_INIT = 128
	JS_EVENT = 'IhBB'
	JS_EVENT_SIZE = calcsize(JS_EVENT)
	def __init__(self, *args):
		threading.Thread.__init__(self)
		log.debug('Preparing joystick plugin...')
		self.setDaemon(True)
		self.setName('JoystickPlugin')
		self.dev = open('/dev/input/js0')
		self.pos = [0, 0]
		self.max_val = 32768
		self.button = events.BUTTON0.post
		self.mouse = events.MOUSE.post
		self.start_pos = None
		descriptor_watch(self.dev.fileno(), self.handle)
		return None

	def _adapt_ratio(self, val):
		return int(100 + (val - self.max_val) * 0.00152587890625)

	def handle(self):
		try:
			evt = self.dev.read(self.JS_EVENT_SIZE)
			time, value, type, number = unpack(self.JS_EVENT, evt)
			evt = type & ~self.JS_EVENT_INIT
		if evt == self.JS_EVENT_AXIS:
			if number == 0:
				self.pos[0] = self._adapt_ratio(value)
			else:
				if number == 1:
					self.pos[1] = self._adapt_ratio(value)
			x, y = self.pos
			if self.start_pos is None:
				self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
			else:
				self.button(dict(x=x, y=y, start_x=self.start_pos[0], start_y=self.start_pos[1]))
				self.mouse(dict(x=x, y=y, timeout=None, clicked=None))
		else:
			if evt == self.JS_EVENT_BUTTON:
				if value:
					self.start_pos = self.pos + []
				else:
					self.start_pos = None



